/**
 * 数据统计管理初始化
 */
var Count = {
    id: "CountTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Count.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        // {title: '序号', field: 'id', align: 'center', valign: 'middle',sortable: true},
        {title: '产品编号', field: 'bianhao', align: 'center', valign: 'middle', sortable: true},
        {title: '简称', field: 'jiancheng', align: 'center', valign: 'middle', sortable: true},
        {title: '首页点击量', field: 'type4', align: 'center', valign: 'middle', sortable: true},
        {title: '推荐产品点击量', field: 'type5', align: 'center', valign: 'middle', sortable: true},
        {title: '详情分享点击量', field: 'type6', align: 'center', valign: 'middle', sortable: true},
        {title: '申请点击量', field: 'type7', align: 'center', valign: 'middle', sortable: true},
        {title: '操作', field: 'jiancheng', align: 'center', valign: 'middle', sortable: true, formatter:function(value,row,index){
            return "<a href='javascript:;' onclick='Count.show("+'"'+value+'"'+")'>查看平台</a>";
        }}
    ];
};
Count.show=function(param){
    location.href=Feng.ctxPath +'/count/query/'+param;
}


Count.Params=function () {
    var queryData = {};
    queryData['jiancheng'] =$("#jiancheng").val();
    return queryData;
}


/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Count.formParams = function() {
    var queryData = {};

    queryData['jiancheng'] =$("#jiancheng").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    return queryData;
}
Count.search = function () {
    Count.table.refresh({query: Count.formParams()});
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/count/listcount/',
        data:Count.formParams(),
        dataType: "json",
        success: function(data){
            $('#type1').empty();
            $('#type2').empty();
            $('#type3').empty();
            $("#type1").html(data.type1);
            $("#type2").html(data.type2);
            $("#type3").html(data.type3);
        }
    });

};
Count.downLoadExcel = function () {
     var param= parseParam(Count.formParams());
    location.href=Feng.ctxPath +'/count/downloadExcel?'+param;
};

var parseParam = function(param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function(i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};


$(function () {
    var defaultColunms = Count.initColumn();
    var table = new BSTable(Count.id, "/count/list", defaultColunms);
    table.setPaginationType("server");
    table.setQueryParams(Count.formParams());
    Count.table = table.init();
    $.ajax({
        type: "GET",
        url: Feng.ctxPath + '/count/listcount/',
        data:Count.formParams(),
        dataType: "json",
        success: function(data){
            $('#type1').empty();
            $('#type2').empty();
            $('#type3').empty();
            $("#type1").html(data.type1);
            $("#type2").html(data.type2);
            $("#type3").html(data.type3);
        }
    });
});

